﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Moving03.Administrator
{
    public partial class WebForm5 : System.Web.UI.Page
    {
        DataClasses1DataContext context = new DataClasses1DataContext();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (User.Identity.IsAuthenticated == false || User.Identity.IsAuthenticated == true && !User.IsInRole("Admin"))
            {
                Response.Redirect("../Default.aspx");
            }
            Label1.Text = "";
        }

        protected void btnthem_Click(object sender, EventArgs e)
        {
            DiaDiemTrungGian ddtg = new DiaDiemTrungGian();
            ddtg.TenDiaDiem = txtdd.Text;
            context.DiaDiemTrungGians.InsertOnSubmit(ddtg);
            context.SubmitChanges();
            GridView1.DataBind();
            txtdd.Text = "";
        }

        protected void GridView1_RowDeleted(object sender, GridViewDeletedEventArgs e)
        {
            if (e.Exception != null)
            {

                Label1.Text = e.Exception.Message;
                e.ExceptionHandled = true;
            }
            else if (e.AffectedRows != 0)
            {
                string a = "<script language='javascript'>  window.alert('Delete Thành Công') </script>";
                Response.Write(a);
                Label1.Text = "";
            }
        }

        protected void GridView1_RowUpdated(object sender, GridViewUpdatedEventArgs e)
        {
            RequiredFieldValidator1.Enabled = true;
        }

        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            RequiredFieldValidator1.Enabled = false;
        }
    }
}